﻿using System;
using System.Drawing;
using System.Windows.Forms;
using bbtpClient.Controllers;
using bbtpClient.Entities;

namespace bbtpClient
{
    public partial class LoginForm : Form
    {
        public Result loginResult;

        public LoginForm()
        {
            InitializeComponent();
            this.loginResult = Result.FAIL;
        }

        private void Startup_Load(object sender, EventArgs e)
        {
            Bitmap image = new Bitmap(@"..\..\startup.bmp", true);
            BackgroundImage = image;
            
        }       

        private void button_Login_Click(object sender, EventArgs e)
        {
            LoginResponse response = LoginController.Login(textBoxLogin.Text, textBoxPassword.Text);
            UserInfo.Name = label_UserName.Text;
            UserInfo.SessionId = response.sessionId;
            UserInfo.Role = response.role;
            this.loginResult = response.result;
            setUserInfo(response);
            this.Close();
        }

        private void setUserInfo(LoginResponse response)
        {
            UserInfo.IsLoggedIn = true;
            UserInfo.Name = textBoxLogin.Text;
            UserInfo.Role = response.role;
            UserInfo.SessionId = response.sessionId;
        }

    }
}